package com.ecfront.test.dao;

import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import com.ecfront.dao.PayDAO;
import com.ecfront.pojo.Pay;
import com.ecfront.pojo.PayGoods;
import com.ecfront.pojo.User;

import junit.framework.TestCase;

public class testPay extends TestCase {
	private static final PayDAO payDao = (PayDAO)SpringUtilTest.getBean("PayDAO");
	//save or update test
	public void testSaveOrUpdate(){
		Pay pay = new Pay();
		pay.setAdd("地狱");
		pay.setCreateDate(new Date());
		pay.setFinishDate(new Date());
		pay.setSendDate(new Date());
		pay.setPayDate(new Date());
		pay.setMonbilePhone("123132");
		pay.setPayBank("中国银行");
		pay.setPayNbr("454654545");
		pay.setPhone("1234579");
		pay.setPrice(121.0);
		pay.setSendCompany("asdsad");
		pay.setSendNbr("asd321321");
		pay.setUsername("张三");
		pay.setZip(314000);
		
		User user = new User();
		user.setId(1);
		pay.setUser(user);
		
		payDao.save(pay);
	}
	//findAll test
	public void testFindAll(){
		List list = payDao.findAll();
		for(Iterator iter = list.iterator();iter.hasNext();){
			Pay pay = (Pay)iter.next();
			System.out.println(pay.getPayBank());
			
			System.out.println(pay.getUser().getName());
		}
	}
	//findById test
	public void testFindById(){
		Pay pay = payDao.findById(1);
		System.out.println(pay.getPayBank());
		System.out.println(pay.getUser().getName());
		
		Set payGoods = pay.getPayGoods();
		for(Iterator iter = payGoods.iterator();iter.hasNext();){
			PayGoods pg = (PayGoods)iter.next();
			System.out.println(pg.getPrice());
			System.out.println(pg.getPay().getUser().getName());
		}
	}
}
